function [ret1,ret2]=push_stack(x,ele)
 if(isTrivial(x.stack,x.tmpsize,ele)==true)
  ret1=0;
  ret2=x;
  return;
 endif
 x.stack{x.tmpsize+1}=ele;
 x.tmpsize=x.tmpsize+1;
 x.mat=x.mat*ele;
 ret1=1;
 ret2=x;
endfunction

function ret=isTrivial(list,l,ele)
 if(l==0)
  ret=false;
  return;
 endif 
 if(list{l}==ele')
  ret=true;
  return;
 endif
 i=0;
 U=ele;
 while i <min(8,l)
  U=U*list{l-i};
  if (distance(U,eye(2))<1e-10) | (distance(U,-eye(2))<1e-10)
   ret=true;
  return;
  endif 
  i=i+1;
 endwhile
 ret=false;
endfunction

